stage.set_background("moon")
sprite = codesters.Sprite("ufo", 0, -220)
sprite.set_size(.5)
time = 6
def left_key():
rotation = sprite.get_rotation()
sprite.set_rotation(rotation+5)
stage.event_key("left", left_key)
def right_key():
rotation = sprite.get_rotation()
sprite.set_rotation(rotation-5)
stage.event_key("right", right_key)
def interval():
global time
if time % 3 == 0:
x = random.randint(-230,230)
y = random.randint(0,230)
planet = codesters.Sprite("jupiter", x, y)
planet.set_size(.3)
time -= 1
stage.event_interval(interval, 1)
def release_key(sprite):
sprite.say("BLAST OFF!", .2, "red")
sprite.move_forward(575)
stage.wait(0.1)
sprite.go_to(0, -210)
# add other actions...
sprite.event_key_release("space", release_key)
stage.wait(12)
stage.clear()
stage.remove_all_events()
question1 = MCQ(1,"","","","","","", "row")
question1.set_prompt(" 1) How often does the interval event in the editor run?")
question1.set_choice_A('every 1 seconds')
question1.set_choice_B('every 6 seconds')
question1.set_choice_C('every 2 seconds')
question1.set_choice_D('every 0.5 seconds')
question1.set_correct("A")
question2 = MCQ(2,"","","","","","", "row")
question2.set_prompt("2) What signals a key event to run?")
question2.set_choice_A('moving the mouse')
question2.set_choice_B('colliding with another sprite')
question2.set_choice_C('a specific amount of time passing')
question2.set_choice_D('pressing a key')
question2.set_correct("D")
question3 = MCQ(3,"","","","","","", "row")
question3.set_prompt("3) Why doesn't anything happen if the UFO hits the planet?")
question3.set_choice_A('There is an error in the collision event')
question3.set_choice_B('We are missing code in the interval event')
question3.set_choice_C('There is no collision event')
question3.set_choice_D('We are missing code in the key release event')
question3.set_correct("C")
repeat_test = True
stop_test = False
def test_script():
global repeat_test
global stop_test
try:
tval1 = question1.correct
except:
tval1 = "DNE"
try:
tval2 = question2.correct
except:
tval2 = "DNE"
try:
tval3 = question3.correct
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == True, " ")
t1.add_failure(tval1 == False, "Q1 wrong")
t1.add_failure(tval1 == "DNE", " ")
t2 = TestObjective()
t2.add_success(tval2 == True, " ")
t2.add_failure(tval2 == False, "Q2 wrong")
t2.add_failure(tval2 == "DNE", " ")
t3 = TestObjective()
t3.add_success(tval3 == True, " ")
t3.add_failure(tval3 == False, "Q3 wrong")
t3.add_failure(tval3 == "DNE", " ")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
#tester.display_first_feedback()
if repeat_test == False:
stop_test = True
test_counter = 0
def repeat_tests():
global stop_test
global test_counter
if stop_test == False:
test_script()
if test_counter >= 100:
stop_test = True
stage.event_interval(repeat_tests, .2)